package com.study.qqclient.service;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;

public class FileService {
    //将文件读取 转为 字节数组
    public static byte[] fileToByteArray(String src) {
        byte[] result = null;
        try {
            FileInputStream fis = new FileInputStream(src);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int len;
            while ((len = fis.read(buffer)) != -1) {
                bos.write(buffer, 0, len);
            }
            result = bos.toByteArray();
            fis.close();
            bos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
